package com.huaao.micropolice.core.repository.system;

import java.util.HashSet;
import java.util.Set;

import org.springframework.stereotype.Repository;

import com.huaao.micropolice.core.model.system.Menu_Subject;
import com.huaao.micropolice.core.model.system.Role;
import com.huaao.micropolice.core.repository.BaseDao;

@Repository
public class MenuSubjectDao extends BaseDao{
	
	public Set<Menu_Subject> filter(Role role , String menuId , String deptId){
		Set<Menu_Subject> filter = new HashSet<Menu_Subject>();
		for(Menu_Subject ms : role.getMenuSubjects()){
			if(ms.getMenu().getId().equals(menuId) && ms.getSubject().getDept().getId().equals(deptId)){//找出菜单，该部门下 role所已经绑定的
				filter.add(ms);
			}
		}
		return filter;
	}
	
	public Set<Menu_Subject> filter(Set<Role> roles, String menuID){
		Set<Menu_Subject> filter = new HashSet<Menu_Subject>();
		for(Role role : roles){
			filter.addAll(filter(role, menuID));
		}
		return filter;
	}
	
	public Set<Menu_Subject> filter(Role role, String menuID){
		Set<Menu_Subject> filter = new HashSet<Menu_Subject>();
		for(Menu_Subject ms : role.getMenuSubjects()){
			if(ms.getMenu().getId().equals(menuID)){//找出菜单，该部门下 role所已经绑定的
				filter.add(ms);
			}
		}
		return filter;
	}
}
